package com.qianfeng.myymatou.app;

import android.app.Application;
import android.content.Context;
import android.graphics.Bitmap;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.squareup.picasso.OkHttpDownloader;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.UrlConnectionDownloader;

/**
 * Created by Administrator on 2016/7/15.
 * <p>
 * 全局初始化
 */
public class IApp extends Application {

    private Context mContext = this;

    //屏幕宽度高度
    public static int mScreenWidth;
    public static int mScreenHeight;

    @Override
    public void onCreate() {
        super.onCreate();

        getScreenScale();

        initImageLoader();

        initPicasso();
    }

    /**
     * 初始化Picasso配置
     */
    private void initPicasso() {
        Picasso picasso = new Picasso.Builder(mContext)
                .defaultBitmapConfig(Bitmap.Config.RGB_565)
                .downloader(new UrlConnectionDownloader(mContext))
                .build();
        Picasso.setSingletonInstance(picasso);
    }

    /**
     * 初始化ImageLoader配置
     */
    private void initImageLoader() {
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext)
                .memoryCacheSize(10 << 20)
                .diskCacheSize(20 << 20)
                .build();
        ImageLoader.getInstance().init(config);
    }

    /**
     * 获取屏幕的宽度高度
     */
    private void getScreenScale() {
        mScreenWidth = getResources().getDisplayMetrics().widthPixels;
        mScreenHeight = getResources().getDisplayMetrics().heightPixels;
    }
}
